package org.scut.smartgeometry.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

/**
 * Created by Administrator on 13-6-28.
 */
public class SaveDialog extends Dialog {

    private SaveCallBack saveCallBack;
    private EditText editText;

    public SaveDialog(Context context, SaveCallBack saveCallBack) {
        super(context);
        this.saveCallBack = saveCallBack;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setTitle("Give a Name");

        LinearLayout linearLayout = new LinearLayout(getContext());
        linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);
        linearLayout.setOrientation(LinearLayout.VERTICAL);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
        );

        editText = new EditText(getContext());
        editText.setTextSize(18);
        linearLayout.addView(editText, p);

        LinearLayout linearLayoutBtn = new LinearLayout(getContext());
        linearLayoutBtn.setOrientation(LinearLayout.HORIZONTAL);
        linearLayoutBtn.setGravity(Gravity.CENTER_HORIZONTAL);

        Button btnOk = new Button(getContext());
        btnOk.setText("ok");
        linearLayoutBtn.addView(btnOk);

        Button btnCancel = new Button(getContext());
        btnCancel.setText("cancel");
        linearLayoutBtn.addView(btnCancel);

        linearLayout.addView(linearLayoutBtn, p);

        setContentView(linearLayout);

        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });


        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = editText.getText().toString();
                if(name.equals("")) name = "default";
                saveCallBack.save(name);
                dismiss();
            }
        });
    }

    public interface SaveCallBack {
        void save(String fileName);
    }
}
